"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_police_index = require("../../../api/police/index.js");
const api_complaint_index = require("../../../api/complaint/index.js");
require("../../../utils/tools.js");
const stores_userInfo = require("../../../stores/userInfo.js");
if (!Array) {
  const _easycom_up_text2 = common_vendor.resolveComponent("up-text");
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_up_form_item2 = common_vendor.resolveComponent("up-form-item");
  const _easycom_up_form2 = common_vendor.resolveComponent("up-form");
  const _easycom_up_gap2 = common_vendor.resolveComponent("up-gap");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_text2 + _easycom_up_input2 + _easycom_up_icon2 + _easycom_up_form_item2 + _easycom_up_form2 + _easycom_up_gap2 + _easycom_up_toast2)();
}
const _easycom_up_text = () => "../../../node-modules/uview-plus/components/u-text/u-text.js";
const _easycom_up_input = () => "../../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_icon = () => "../../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_up_form_item = () => "../../../node-modules/uview-plus/components/u-form-item/u-form-item.js";
const _easycom_up_form = () => "../../../node-modules/uview-plus/components/u-form/u-form.js";
const _easycom_up_gap = () => "../../../node-modules/uview-plus/components/u-gap/u-gap.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_text + _easycom_up_input + _easycom_up_icon + _easycom_up_form_item + _easycom_up_form + _easycom_up_gap + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "addComplaint",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const formData = common_vendor.reactive({
      form: {
        communityId: userInfoStore.crowdInfo.communityId,
        content: "",
        imgUrl: "",
        policeIds: [],
        policeUsers: void 0
      },
      rules: {
        policeIds: {
          type: "array",
          required: true,
          message: "请选择投诉对象",
          trigger: ["blur", "change"]
        },
        content: [
          {
            type: "string",
            required: true,
            message: "请填写投诉内容",
            trigger: ["blur", "change"]
          },
          {
            type: "string",
            max: 100,
            required: true,
            message: "请限制投诉内容在100字符内！",
            trigger: ["blur", "change"]
          }
        ]
      }
    });
    const { form, rules } = common_vendor.toRefs(formData);
    const uForm = common_vendor.ref(null);
    const fileList = common_vendor.ref([]);
    common_vendor.ref([]);
    const selectUser = () => {
      common_vendor.index.hideKeyboard();
      setTimeout(() => {
        common_vendor.index.navigateTo({
          url: `/subPages/crowd/serviceEvaluation/selectUser?users=${form.value.policeIds.join(
            ","
          )}`
        });
      }, 100);
    };
    const getPoliceList = () => {
      api_police_index.policeListByCommunityId({ communityId: userInfoStore.crowdInfo.communityId }).then((res) => {
        const { data } = res;
        let arr = data ?? [];
        if (arr.length === 1) {
          form.value.policeIds = [arr[0].policeUserId];
          form.value.policeUsers = [arr[0].userName + " " + arr[0].badgeNumber];
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const onsubmit = () => {
      let arr = [];
      if (fileList.value.length) {
        fileList.value.forEach((item) => {
          arr.push(item.fileUrl);
        });
      }
      form.value.imgUrl = arr.join(",");
      uForm.value.validate().then((res) => {
        common_vendor.index.showLoading({
          title: "提交中",
          mask: true
        });
        api_complaint_index.addComplaint(form.value).then((res2) => {
          common_vendor.index.hideLoading();
          uToastRef.value.show({
            type: "success",
            message: "提交成功"
          });
          let timer = setTimeout(() => {
            common_vendor.index.navigateBack({
              delta: 1
            });
            clearTimeout(timer);
          }, 1500);
        }).catch((err) => {
          common_vendor.index.hideLoading();
          uToastRef.value.show({
            type: "error",
            message: err
          });
        });
      }).catch(() => {
      });
    };
    common_vendor.onShow(() => {
      common_vendor.index.$on("updateServiceUser", (data) => {
        form.value.policeIds = data.selectUserIds;
        form.value.policeUsers = data.policeUsers;
      });
    });
    common_vendor.onHide(() => {
      common_vendor.index.hideKeyboard();
    });
    common_vendor.onLoad(() => {
      getPoliceList();
    });
    common_vendor.onReady(() => {
      uForm.value.setRules(rules.value);
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.p({
          prefixIcon: "info-circle-fill",
          iconStyle: {
            fontSize: "16px",
            color: "#ff9900"
          },
          size: "14",
          text: "此投诉为本小程序自有投诉渠道，非微信官方投诉渠道"
        }),
        b: common_vendor.o(($event) => common_vendor.unref(form).policeUsers = $event),
        c: common_vendor.p({
          disabled: true,
          disabledColor: "#ffffff",
          placeholder: "请选择投诉对象",
          border: "none",
          color: "#000000",
          inputAlign: "right",
          placeholderStyle: "{color: '#707070'}",
          modelValue: common_vendor.unref(form).policeUsers
        }),
        d: common_vendor.p({
          name: "arrow-right",
          color: "#000000"
        }),
        e: common_vendor.o(($event) => selectUser()),
        f: common_vendor.p({
          label: "投诉对象",
          borderBottom: true,
          required: true,
          prop: "policeIds"
        }),
        g: common_vendor.t(common_vendor.unref(form).content.length),
        h: common_vendor.unref(form).content,
        i: common_vendor.o(($event) => common_vendor.unref(form).content = $event.detail.value),
        j: common_vendor.p({
          label: "投诉内容",
          required: true,
          prop: "content"
        }),
        k: common_vendor.sr(uForm, "4e774d52-1", {
          "k": "uForm"
        }),
        l: common_vendor.p({
          labelPosition: "left",
          model: common_vendor.unref(form),
          rules: common_vendor.unref(rules),
          labelWidth: "75"
        }),
        m: common_vendor.o(onsubmit),
        n: common_vendor.p({
          height: "50"
        }),
        o: common_vendor.sr(uToastRef, "4e774d52-7", {
          "k": "uToastRef"
        })
      };
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4e774d52"]]);
wx.createPage(MiniProgramPage);
